<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends BaseController{
    public function index(){
        // 获取博客栏目
        $cats = M('cat')->order('sort desc,cat_id desc')->limit(1)->select();
        
        // 获取博客
        if (!empty(I('get.cat_id'))){
            $cat_id = I('get.cat_id');
            $cat_name = M('cat')->where(array('cat_id'=>$cat_id))->getField('cat_name');
        }else {
            $cat_id = $cats[0]['cat_id'];
            $cat_name = $cats[0]['cat_name'];
        }
        
        
        // 获取5篇最热的文章
        $blog_M = M('blog');
        
        // 设置分页
        $blogs = $blog_M->where(array('cat_id'=>$cat_id))->limit(7)->select();
        
        // 传递数据
        $this->assign('blogs',$blogs);
        $this->assign('cat_name',$cat_name);
        
        $this->display();
    }
    
    public function test(){
        
        // 获取新闻
        
    }
}